home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / doSubdivAttachArgList.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.8 KB  |  220 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Description:
  22. //      Functions called from "Subdiv Attach".
  23. //
  24.  
  25. proc int simulatePerformPolySewEdge( float $fval, int $ivSM, int $ivWS)
  26. {
  27.     // looks exactly like performPolySewEdge, but with custom args 
  28.     string $cmd = "";
  29.     $cmd=("polySewEdge -t " + $fval + " -tx " + $ivSM + " -ws " + $ivWS);
  30.     // Get the current value of the "Convert Selection" option var. Then
  31.     // set the value of the optionVar to do the selection conversion and
  32.     // finally set it back to the original value, after the operation has
  33.     // been performed. This so that the operation succeeds when the object
  34.     // (not edges) is selected and "Convert Selection" is not toggled on
  35.     // bug #149414.
  36.     //
  37.     int $origConvertSelVarValue = `optionVar -query polyAutoConvertAction`;
  38.     optionVar -intValue polyAutoConvertAction 1;
  39.     polyPerformAction $cmd e 0;
  40.     // Set the "Convert Selection" option var back to original state.
  41.     //
  42.     optionVar -intValue polyAutoConvertAction $origConvertSelVarValue;
  43.     return 0;
  44. }
  45.  
  46. //
  47. //  Procedure Name:
  48. //      doSubdivAttachArgList
  49. //
  50. //  Description:
  51. //        This is the actual function that gets called from "Subdiv Attach" 
  52. //      option box.
  53. //
  54. //  Input Arguments:
  55. //        $version: The version of this option box.  This is used to know how to 
  56. //                  interpret the $args array.
  57. //
  58. //      history (args[0])
  59. //      sew edge threshold (args[1])  (aka $fval)
  60. //      sew map edge (args[2])            (aka $ivSM)
  61. //      sew edge world space (args[3])  (aka $ivWS)
  62. //
  63. //  Return Value:
  64. //      0 if we succeeded, >0 otherwise.
  65. //
  66. //  Note:  
  67. //
  68. global proc int doSubdivAttachArgList( string $version, string $args[] )
  69. {
  70.     int $status = 1;
  71.  
  72.     if( size($args) < 1 ) {
  73.         error("Incorrect doSubdivAttachArgList \"1\" number of arguments.");
  74.         return $status;
  75.     }
  76.  
  77.     global int $gSelectSubdivSurface;
  78.  
  79.     // attach all subd's
  80.     string $list[] = `filterExpand -ex 1 -fp 1 -sm $gSelectSubdivSurface`; 
  81.     int $len = size($list);
  82.  
  83.     if( $len < 2) {
  84.         error ("Select two subdivision surfaces " +
  85.                "that you want to attach.");
  86.         return $status;
  87.     }
  88.  
  89.     int $globalHist = $args[0];
  90.     float $fval = $args[1];
  91.     int $ivSM = $args[2];
  92.     int $ivWS = $args[3];
  93.     int $delOrig = $args[4];
  94.     string $subd1 = $list[0];
  95.     string $subd2 = $list[1];
  96.  
  97.     int $whichMode = `subdiv -q -proxyMode $subd1`;
  98.     if( 2 == $whichMode ) {
  99.         error( "Cannot attach and merge subdivision surfaces " +
  100.                "with construction history and/or deformers." );
  101.         return $status;
  102.     }
  103.     else if( 1 == $whichMode ) {
  104.         error( "Cannot attach and merge subdivision surfaces " +
  105.                "in polygon proxy mode." );
  106.         return $status;
  107.     }
  108.  
  109.     $whichMode = `subdiv -q -proxyMode $subd2`;
  110.     if( 2 == $whichMode ) {
  111.         error( "Cannot attach and merge subdivision surfaces " +
  112.                "with construction history and/or deformers." );
  113.         return $status;
  114.     }
  115.     else if( 1 == $whichMode ) {
  116.         error( "Cannot attach and merge subdivision surfaces " +
  117.                "in polygon proxy mode." );
  118.         return $status;
  119.     }
  120.  
  121.     waitCursor -st on;
  122.     // trace( "// Processing " + $subd1 + " ...\n" );
  123.     string $res1 = subdGivenIntoPolyMode( $subd1, $globalHist, 0, 0, 1 );
  124.     waitCursor -st off;
  125.  
  126.     // trace( "// Processing " + $subd2 + " ...\n" );
  127.     waitCursor -st on;
  128.     string $res2 = subdGivenIntoPolyMode( $subd2, $globalHist, 0, 0, 1 );
  129.     waitCursor -st off;
  130.  
  131.     // trace( "// Combining " + $res1 + " and " + $res2 + " ...\n" );
  132.     waitCursor -st on;
  133.     // Perform the unite operation with history toggled on.. This is
  134.     // much more efficient because deleting history results in a couple
  135.     // of very expensive data (including blindData) computations.
  136.     // Part of bug #148350.
  137.     //
  138.     string $newPoly[] = `polyUnite -ch 1 $res1 $res2`;
  139.     waitCursor -st off;
  140.     if( size($newPoly) > 0 ) {
  141.         // Too much stuff going on; we have to just go with
  142.         // the Sew edge and hope for the best...
  143.         select -r $newPoly[0];
  144.         // trace( "// Merging multiple edges on " + $newPoly[0] + " ...\n" );
  145.         waitCursor -st on;
  146.  
  147.         simulatePerformPolySewEdge( $fval, $ivSM, $ivWS );
  148.         waitCursor -st off;
  149.         select -r $newPoly[0];
  150.  
  151.         // trace( "// Creating the resulting subdivision surface.\n" );
  152.         waitCursor -st on;
  153.         doSubdivCreate( "3", { "1", "0", "10000", "128", "1" } );
  154.  
  155.         // Now delete the temporary polys that were created to perform
  156.         // the unite operation.
  157.         //
  158.         delete $res1 $res2;
  159.  
  160.         if( $delOrig ) {
  161.             // Delete the original surfaces.. They get deleted along with
  162.             // their parent transform, if the parent transform does not have
  163.             // any other children.. Else, the surface gets deleted, leaving
  164.             // the parent transform untouched. All this happens only if there
  165.             // is no instancing above the shape..
  166.             //
  167.             string $parents[] = `listRelatives -parent $subd1`;
  168.             if( size($parents) == 1 ) {
  169.                 string $children[] = `listRelatives -children $parents[0]`;
  170.                 if( size($children) == 1 ) {
  171.                     // Parent transform has one child.. Delete both the
  172.                     // transform and child (subd surface)..
  173.                     //
  174.                     delete $parents[0];
  175.                 }
  176.                 else {
  177.                     // Parent transform has multiple children.. Play it safe
  178.                     // and just delete the subd surface..
  179.                     //
  180.                     delete $subd1;
  181.                 }
  182.             }
  183.             else {
  184.                 warning( "Cannot delete instanced original shape." );
  185.             }
  186.             // Repeat this for $subd2
  187.             //
  188.             $parents = `listRelatives -parent $subd2`;
  189.             if( size($parents) == 1 ) {
  190.                 $children = `listRelatives -children $parents[0]`;
  191.                 if( size($children) == 1 ) {
  192.                     // Parent transform has one child.. Delete both the
  193.                     // transform and child (subd surface)..
  194.                     //
  195.                     delete $parents[0];
  196.                 }
  197.                 else {
  198.                     // Parent transform has multiple children.. Play it safe
  199.                     // and just delete the subd surface..
  200.                     //
  201.                     delete $subd2;
  202.                 }
  203.             }
  204.             else {
  205.                 warning( "Cannot delete instanced original shape." );
  206.             }
  207.         }
  208.         waitCursor -st off;
  209.         $status = 0;
  210.     }
  211.     else {
  212.         error( "Polygon combine failed" );
  213.     }
  214.     setSelectMode objects Objects;
  215.  
  216.     return $status;
  217. }
  218.  
  219.  
  220.